package com.ds.seqlist.LeetCode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/9/4 19:28
 */
public class Num155_MinStack {
    Deque<Integer> xStack;
    Deque<Integer> minStack;

    public Num155_MinStack() {
        xStack = new LinkedList<Integer>();
        minStack = new LinkedList<Integer>();
        minStack.push(Integer.MAX_VALUE);//不加会导致空指针异常，minStack空的时候获取peek会空指针
    }

    public void push(int x) {
        xStack.push(x);
        minStack.push(Math.min(minStack.peek(), x));
    }

    public void pop() {
        xStack.pop();
        minStack.pop();
    }

    public int top() {
        return xStack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }

}
